package com.rr.middle;

/**
 * @author zhuangcanrun
 * @Date 2022/06/23/20:22
 * @description
 **/
/*
* https://leetcode.cn/problems/container-with-most-water/submissions/
* 算出最大的矩形面积
* */
public class MaxArea {
    public int maxArea(int[] height) {
        int length = height.length;
        int ans = 0;
        int leftMax = 0;
        for (int i = 0; i < length; i++) {
            int left = height[i];
            //后面的左边还没原来的左边大，可以直接跳过
            if (left < leftMax) {
                continue;
            }
            leftMax = left;
            int rightMax = 0;
            if (left == 0) {
                continue;
            }
            for (int j = length - 1; j > i; j--) {
                if (height[j] >= left) {
                    ans = Math.max(ans, (j - i) * left);
                } else if (height[j] > rightMax) {
                    rightMax = height[j];
                    ans = Math.max(ans, (j - i) * rightMax);
                }
            }
        }
        return ans;
    }
}
